package com.sss.hloster0402;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.jupiter.api.Test;

public class TestDriver {//对象流
	@Test
	public void test03() {//对象输出流
		//创建一个新的实例对象
		
		try (
			ObjectOutputStream  os=new ObjectOutputStream(new FileOutputStream("E:\\Download\\streamfiles/in01.dat"));
				ObjectInputStream  is=new ObjectInputStream(new FileInputStream("E:\\Download\\streamfiles/in01.dat"));
				){
			Student st01=new Student("王林","150042",80);
			//写出对象
			os.writeObject(st01);
			System.out.println("写出对象内容：："+st01);
			Object st02=is.readObject();
			
			System.out.println("读入的对象内容："+st02);
			System.out.println("st01  ==  st02::"+(st01==st02));
	} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void test02() {//对象输入流
		
		try (
			ObjectInputStream  is=new ObjectInputStream(new FileInputStream("E:\\Download\\streamfiles/in01.dat"));
				){
			//将对象读入
			Object stu=is.readObject();
			System.out.println("读入的对象内容："+stu);
			
	} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void test01() {//对象输出流
		//创建一个新的实例对象
		Student st=new Student("王林","150042",80);
		try (
			ObjectOutputStream  os=new ObjectOutputStream(new FileOutputStream("E:\\Download\\streamfiles/in01.dat"));
				){
			//写出对象
			os.writeObject(st);
			System.out.println("<<<<>>>>");
			
	} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
